package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.CustomerBean;
import com.zzj.dao.CustomerDao;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerDao customerDao;

    @Override
    public boolean addCustomer(CustomerBean customerBean) {
        int i = customerDao.addCustomer(customerBean);
        return i == 1;
    }

    @Override
    public PageInfo<CustomerBean> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CustomerBean> all = customerDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result updateCustomer(CustomerBean customerBean) {
        int i = customerDao.updateCustomer(customerBean);
        if (i == 1){
            return new Result();
        }
        return new Result(false, StatusCode.ERROR,"操作失败");
    }
}
